import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { viteMockServe } from "vite-plugin-mock";

// https://vitejs.dev/config/
export default defineConfig({
	base: "./",
	plugins: [
		react(),
		// mock配置
		viteMockServe({
			supportTs: true,
			watchFiles: false, // 是否实时更新
			logger: false,
			mockPath: "./src/mock/"
		})
	],
	resolve: {
		// 配置别名
		alias: {
			"@": path.resolve(__dirname, "src")
		}
	},
	// server config
	server: {
		host: "0.0.0.0", // 服务器主机名，如果允许外部访问，可设置为"0.0.0.0"
		port: 3001,
		open: true, // 自动打开浏览器
		cors: true,
		// 代理跨域
		proxy: {
			"/apis": {
				target: "http://localhost:3001",
				changeOrigin: true,
				rewrite: path => path.replace(/^\/apis/, "")
			}
		}
	}
});
